#ifndef _DISKFMT_
#define _DISKFMT_

#include <type.h>

struct BPB_struct	{
	u8 jmpBoot;
	u16 jmpoff;
	u8 OEMName[8];
	u16 BytsPerSec;
	u8 SecPerClus; //Sector per cluster
	u16 ResvdSecCnt;		//Reserved sector count
	u8 NumFATs;		//No. of FAT structures
	u16 RootEntCnt;
	u16 TotSec16;
	u8 Media;
	u16 FATSz16;
	u16 SecPerTrk;
	u16 NumHeads;
	u32 HiddSec;
	u32 TotSec32;
}__attribute__((packed));

struct BPB_struct_FAT32	{
	u32 FATSz32;
	u16 ExtFlags;
	u16 FSVer;
	u32 RootClus;			//First cluster of the root directory
	u16 FSInfo;
	u16 BkBootSec;
	u8 Reserved[12];
	u8 DrvNum;
	u8 Reserved1;
	u8 BootSig;
	u32 VolID;
	u8 VolLab[11];
	u8 FilSysType[8];
}__attribute__((packed));

struct FSI_struct	{
	u32 LeadSig;
	u8 Reserved1[480];
	u32 StrucSig;
	u32 Free_Count;
	u32 Nxt_Free;
	u8 Reserved2[12];
	u32 TrailSig;
}__attribute__((packed));

struct DIR_struct	{
	u8 Name[11];
	u8 Attr;
	u8 NTRes;		//Reserved by NT
	u8 CrtTimeTenth;  //File Creation tenth of a sec
	u16 CrtTime;		//File creation time
	u16 CrtDate;
	u16 LstAccDate;
	u16 FstClusHI;		//High of start cluster
	u16 WrtTime;
	u16 WrtDate;
	u16 FstClusLO;		//Low of start cluster
	u32 FileSize;
}__attribute__((packed));

struct LDIR_struct	{
	u8 Ord;
	u8 Name1[10];
	u8 Attr;
	u8 Type;
	u8 Chksum;
	u8 Name2[12];
	u16 FstClusLO;
	u8 Name3[4];
}__attribute__((packed));

#ifndef _DISK_VOLUME_STRUCT_
#define _DISK_VOLUME_STRUCT_

typedef struct {
	u32 start_lba;
	u32 len_lba;
	u32 current_cluster;
	char system[20];
	struct BPB_struct BPB;
	struct BPB_struct_FAT32 BPB_fat32;
	struct FSI_struct FSI;
}disk_volume;

#endif

int query_open_(char *name);
u8 *open_(char *name);
void read_bpb(disk_volume *vol); 
int read_fsinfo(disk_volume *vol);
int set_volume(disk_volume *vol);

#endif
